package jianli;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet("/WelcomeServlet")
public class WelcomeServlet extends HttpServlet{
    private static final long serialVersionUID = 1L;
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        HttpSession session=request.getSession();
        out.println("<HTML>");
        out.println("  <HEAD><TITLE>东软集团欢迎您！</TITLE></HEAD>");
        out.println("  <BODY>");
        if("wyj".equals((String)session.getAttribute("username"))){//取得会话属性
            out.println("<h3>欢迎"+session.getAttribute("username"));
            out.println("<h3><a href='GiftServlet'>看看访问次数是否达到5次了，看看有没有礼品拿，顺便看一下session信息</a></h3>");
            }else{
            //out.println("<h3>请先进行系统的<a href='login.jsp'>登录</a>!</h3>");
            //response.setHeader("refresh","1;URL=login.jsp");//客户端跳转，定时刷新
            //response.sendRedirect("login.jsp");//重定向，客户端跳转，即刻跳转
            request.getRequestDispatcher("login.jsp").forward(request, response);//服务器端跳转
        }
        out.println("</BODY>");
        out.println("</HTML>");
    }
}